package com.zx.club.oss.config;

import com.zx.club.oss.adapter.AliStorageServiceAdapter;
import com.zx.club.oss.adapter.StorageServiceAdapter;
import com.zx.club.oss.util.AliOssUtil;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 
 * @author zx
 * @date 2025-03-20 09:26
 */
@Configuration
@ConditionalOnProperty(prefix = "oss", name = "type", havingValue = "aliOss")
@Slf4j
public class AliConfig {

    @Resource
    private OssProperties ossProperty;

    @Bean
    public AliOssUtil aliOssUtil(){
        AliOssProperties aliOssProperties = ossProperty.getAliOss();
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }

    @Bean("aliStorageService")
    public StorageServiceAdapter StorageServiceAdapter(AliOssUtil aliOssUtil){
        return new AliStorageServiceAdapter(aliOssUtil);
    }
}
